home *** CD-ROM | disk | FTP | other *** search
- #include<math.h>
- int errno;
-
- void mult(); /*out matrix mult proc*/
- /*floating value of points to avoid roundoff*/
- typedef struct rec {float h,v;} points;
- main()
- {
- int buttondown=0, /*flagg for mouse */
- n=-1, /*number of vertices */
- keypressed=0, /*flagg for key */
- flip=0, /*to allow alternating */
- flop=1, /*vertices to be drawn */
- i; /*array counter */
- float x, /*angle counter */
- T[3][3], /*translation matrix */
- Tinv[3][3], /*translate back */
- Rz[3][3], /*rotate matrix */
- c[3][3], /*result of T&R */
- d[3][3]; /*result of c&Tinv */
- long curtick, /*for delay loop */
- lastick; /*for delay loop */
- EventRecord nextevent;/*to get mouse&key */
- Point origin,dummy; /*pivot and locator */
- points points[2][30];/*vertices(don’t draw
- the Eiffel tower) */
- WindowPtr scnwdw; /*window pointer */
- Rect scnrect; /*window rect */
- /*************************************
- * Set things up *
- *************************************/
- InitGraf(&thePort);
- InitFonts();
- InitWindows();
- InitDialogs((Ptr)0L);
- TEInit();
- InitMenus();
- scnrect=screenBits.bounds;
- InsetRect(&scnrect,10,25);
- scnwdw=NewWindow(0,&scnrect,"\p",TRUE,dBoxProc,
- -1,FALSE,0);
- SetPort(scnwdw);
- InitCursor();
-
- /*************************************
- * Get points *
- *************************************/
- while(!keypressed)
- {
- buttondown=0;
- SystemTask();
- if(GetNextEvent(-1,&nextevent))
- if(nextevent.what==mouseDown) buttondown=1;
- else if(nextevent.what==keyDown) keypressed=1;
- if(buttondown) /*get a point and draw it*/
- {
- GetMouse(&dummy);
- points[0][++n].h=dummy.h;points[0][n].v=dummy.v;
- if(n==0)
- MoveTo((int)points[0][0].h,(int)points[0][0].v);
- LineTo((int)points[0][n].h,(int)points[0][n].v);
- } /*end of get point*/
- } /*end of get points*/
-
- /*************************************
- * Get origin *
- *************************************/
- buttondown=0;
- do
- {
- SystemTask();
- if(GetNextEvent(-1,&nextevent))
- if(nextevent.what==mouseDown) buttondown=1;
- }while(!buttondown);
- GetMouse(&origin);
-
- /*************************************
- * Make translation matrix *
- *************************************/
- T[0][0]=1;T[0][1]=0;T[0][2]=0;
- T[1][0]=0;T[1][1]=1;T[1][2]=0;
- T[2][0]=-origin.h;T[2][1]=-origin.v;T[2][2]=1;
- Tinv[0][0]=1;Tinv[0][1]=0;Tinv[0][2]=0;
- Tinv[1][0]=0;Tinv[1][1]=1;Tinv[1][2]=0;
- Tinv[2][0]=origin.h;Tinv[2][1]=origin.v;Tinv[2][2]=1;
- Rz[0][2]=0;Rz[1][2]=0;Rz[2][0]=0;Rz[2][1]=0;Rz[2][2]=1;
-
- /*************************************
- * Rotate *
- *************************************/
- x=0.157; /*rotation angle - about 9 degrees*/
- Rz[0][0]=Rz[1][1]=cos(x);Rz[0][1]=sin(x);
- Rz[1][0]=-Rz[0][1];
- mult(T,Rz,c);
- mult(c,Tinv,d);
- for(x=.157;x<=12.56;x+=0.157)
- {
- flip++;flip=flip%2;flop++;flop=flop%2;
- for(i=0;i<=n;i++)
- {
- points[flip][i].h=points[flop][i].h*d[0][0]
- +points[flop][i].v*d[1][0]
- +1*d[2][0];
- points[flip][i].v=points[flop][i].h*d[0][1]
- +points[flop][i].v*d[1][1]
- +1*d[2][1];
- } /*end update points*/
- ForeColor(whiteColor); /*undraw flop*/
- lastick=TickCount(); /*time delay for retace to improve animation*/
- do{curtick=TickCount();} while(lastick+1>curtick);
- MoveTo((int)points[flop][0].h,(int)points[flop][0].v);
- for(i=1;i<=n;i++) LineTo((int)points[flop][i].h,(int)points[flop][i].v);
- ForeColor(blackColor); /*draw flip*/
- lastick=TickCount();
- do{curtick=TickCount();} while(lastick+1>curtick);
- MoveTo((int)points[flip][0].h,(int)points[flip][0].v);
- for(i=1;i<=n;i++) LineTo((int)points[flip][i].h,(int)points[flip][i].v);
- } /*end rotate*/
-
- /*************************************
- * End everything *
- *************************************/
- buttondown=0;
- do
- {
- SystemTask();
- if(GetNextEvent(-1,&nextevent))
- if(nextevent.what==mouseDown) buttondown=1;
- }while(!buttondown);
-
- DisposeWindow(scnwdw);
-
- } /*program end*/
-
- void mult(A,B,C)
- float A[][3],B[][3],C[][3];
- {
- int i,j,k;
-
- for(i=0;i<=2;i++)
- for(j=0;j<=2;j++)
- {
- C[i][j]=0.0;
- for(k=0;k<=2;k++)
- C[i][j]+=A[i][k]*B[k][j];
- }
- } /*end mult*/
-
-
-
-
-
-
-
-
-
-